<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 了解 -->
    <div id="app">
      <my-test></my-test>
      <hr />

      <!-- 异步组件在加载过程中显示地内容 -->
      <!-- 要配合fallback的具名插槽 -->
      <suspense>
        <my-com></my-com>
        <template #fallback>
          <span>loading...</span>
        </template>
      </suspense>
    </div>

    <script src="./lib/vue3.js"></script>
    <script>
      const { createApp, defineAsyncComponent } = Vue;

      const Com = {
        template: "<div>这是子组件</div>",
      };
      const MyCom = defineAsyncComponent(() => {
        return new Promise((resolve, reject) => {
          setTimeout(() => {
            resolve(Com);
          }, 3000);
        });
      });

      createApp({
        data() {
          return {};
        },
        components: {
          MyCom,
          MyTest: Com,
        },
      }).mount("#app");
    </script>
  </body>
</html>
